using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using ConfigManager.Core;
using NUnit.Framework;

namespace ConfigManager.Tests
{
    [TestFixture()]
    public class XmlInstructionParserTests
    {
        [Test()]
        public void ParseParametersTests()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("key1=\"value1\"");
            builder.Append("key2=\"value1\"");
            builder.Append("   key3=\"value3\"  key4=\"value4\"       key5=\"value5\"     ");

            Object obj = Reflection.InvokeStaticMethod("ParseParameters", 
                typeof(XmlInstructionParser), new object[] {builder.ToString()});

            IDictionary<string, string> dict = (IDictionary<string, string>) obj;
            Assert.AreEqual(5, dict.Count);

        }

        [Test()]
        public void RegexTest()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("key1=\"value1\"");
            builder.Append("key2=\"value1\"");
            builder.Append("   key3=\"value3\"  key4=\"value4\"       key5=\"value5\"     ");

            //string pattern = @"Attributes=\(((?'type'\w+)(=)(?'value'\w+)\;\s?)+\)";
            //string pattern = @"((?'type'\w+)(=)(?'value'\w+)\s?)+";
            string pattern =String.Format(@"(?<name>.*?)={0}(?<val>.*?){0}", Regex.Escape("\""));

            MatchCollection matches = Regex.Matches(builder.ToString(), pattern);
            foreach (Match match in matches)
            {
                string key = match.Groups["name"].Value;
                string val = match.Groups["val"].Value;
                //foreach (Group g in match.Groups)
                //{
                //    Console.Out.WriteLine(g.Value);
                //}
                
            }


            Assert.AreEqual(5, matches.Count);
        }


        //   private static IDictionary<string, string> ParseInstructionParameters(string comment, string instName)
        
    }
}
